Set Up Steps

library(censusapi)
library(colorspace)
library(dplyr)
library(jsonlite)
library(mapview)
library(raster)
library(rgeos)
library(readr)
library(stringr)
library(sf)
library(sp)
library(tidycensus)
library(tidyverse)
library(tigris)
library(usmap)
library(leaflet)
library(tmap)
library(shinyjs)
library(png)
library(purrr)

census_api_key <- "5e188bf6fd2d0fbf95ecabc753b82960d946530f"
# Sys.getenv("CENSUS_KEY")

mapview::mapviewOptions(basemaps = "OpenStreetMap")
options(
  tigris_class = "sf",
  tigris_use_cache = TRUE
)
# mapviewOptions(basemaps = "OpenStreetMap")
counties = c("Alameda", "Contra Costa", "Marin", "Napa", "San Francisco", "San Mateo", "Santa Clara", "Sonoma", "Solano")
food_access <-
  read_csv("/Users/armellecoutant/Documents/GitHub/218z/SNAP/DataDownload2015.csv")

SNAP Recipients

This is a map of SNAP Recipient housing units as a percent of total Census Tract housing units.

bay_snap <-
  food_access %>%
  dplyr::select(CensusTract, State, County, Urban, POP2010, OHU2010, TractSNAP) %>%
  filter(County %in% counties)

bay_snap <-
  bay_snap %>%
  mutate(
    PercentSNAP = (TractSNAP/OHU2010)*100
  )

us <- unique(fips_codes$state)[1:51]

tracts <- reduce(
  map(us, function(x) {
    get_acs(geography = "tract", variables = "B01003_001",
            state = x, geometry = TRUE)
  }),
  rbind
)
str(tracts)
## Classes 'sf' and 'data.frame':   73056 obs. of  6 variables:
##  $ GEOID   : chr  "01001020100" "01001020200" "01001020300" "01001020400" ...
##  $ NAME    : chr  "Census Tract 201, Autauga County, Alabama" "Census Tract 202, Autauga County, Alabama" "Census Tract 203, Autauga County, Alabama" "Census Tract 204, Autauga County, Alabama" ...
##  $ variable: chr  "B01003_001" "B01003_001" "B01003_001" "B01003_001" ...
##  $ estimate: num  1845 2172 3385 4267 9965 ...
##  $ moe     : num  199 271 400 466 802 346 332 240 659 519 ...
##  $ geometry:sfc_GEOMETRY of length 73056; first list element: List of 1
##   ..$ :List of 1
##   .. ..$ : num [1:53, 1:2] -86.5 -86.5 -86.5 -86.5 -86.5 ...
##   ..- attr(*, "class")= chr  "XY" "MULTIPOLYGON" "sfg"
##  - attr(*, "sf_column")= chr "geometry"
##  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA
##   ..- attr(*, "names")= chr  "GEOID" "NAME" "variable" "estimate" ...
bay_snap_tracts <-
  tracts %>%
  left_join(bay_snap, by = c("GEOID" = "CensusTract")) %>%
  na.omit()

mapview(bay_snap_tracts, zcol = "PercentSNAP")

This is a bar chart of SNAP Recipient demographics by County.

Poverty Rate

This is a map of poverty rates.

bay_poverty <-
  food_access %>%
  dplyr::select(CensusTract, State, County, Urban, PovertyRate) %>%
  filter(County %in% counties)

bay_poverty_tracts <-
  tracts %>%
  left_join(bay_poverty, by = c("GEOID" = "CensusTract")) %>%
  na.omit()

mapview(bay_poverty_tracts, zcol = "PovertyRate")

SNAP Retailer Availability

This is a map of the areas with the most housing units per SNAP retailer.

Low Vehicle Access

This is a map of low vehicle access. Low vehicle households were defined as households without a vehicle and with no supermarkets within 1/2 mile. Low vehicle census tracts were defined as census tracts with > 100 low vehicle access households.

Prevalence of Food Deserts

Low food access was defined as having no supermarkets within 1 mile for urban areas and within 10 miles for rural areas.

Health Indicators